import { CellRenderer } from "../../../../fl/controls/listClasses/CellRenderer";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { GLabel } from "../../../../com/mui/controls/GLabel";
import { ObjCreate } from "../common/ObjCreate";
import { SPublicMiniPlayer } from "../../../../Message/Public/SPublicMiniPlayer";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { Cache } from "../../cache/Cache";
import { CareerConfig } from "../../resource/CareerConfig";
import { EntityUtil } from "../../scene/layer/utils/EntityUtil";
import { Language } from "../../../../extend/language/Language";
import { Alert } from "../../../../com/mui/controls/Alert";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GButton } from "../../../../com/mui/controls/GButton";
type int = number;
//class GroupPlayerCellRenderer
    
    export  class GroupPlayerCellRenderer extends CellRenderer
    {
        constructor()
        {
            super();
            this.mouseChildren = true;
            this.initStyle();
            this.createChildren();
            return;
        }

        /* internal  */initStyle(): void
        {
            this.setStyle("upSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("downSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("overSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedDownSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedOverSkin", new Object /* flash.display.Bitmap */());
            this.setStyle("selectedUpSkin", new Object /* flash.display.Bitmap */());
            return;
        }

        /* internal  */createChildren(): void
        {
            var loc1=ResouceConst.getScaleBitmap("SplitLine");
            loc1.width = 218;
            loc1.y = 36;
            this.addChild(loc1);
            this._captainIcon = GlobalClass.getBitmap(ImagesConst.GroupCaptainIcon);
            this._captainIcon.x = 10;
            this._captainIcon.y = 10;
            this.addChild(this._captainIcon);
            this.nameLabel = new GLabel();
            addChild(this.nameLabel);
            this.nameLabel.setSize(92, 22);
            this.nameLabel.x = 30;
            this.nameLabel.y = 9;
            this.nameLabel.mouseEnabled = false;
            this.levelLabel = new GLabel();
            addChild(this.levelLabel);
            this.levelLabel.setSize(30, 22);
            this.levelLabel.x = 110;
            this.levelLabel.y = 9;
            this.levelLabel.mouseEnabled = false;
            this.careerLabel = new GLabel();
            addChild(this.careerLabel);
            this.careerLabel.setSize(76, 22);
            this.careerLabel.x = 133;
            this.careerLabel.y = 9;
            this.careerLabel.mouseEnabled = false;
            this.processLabel = new GLabel();
            addChild(this.processLabel);
            this.processLabel.setSize(40, 22);
            this.processLabel.x = 163;
            this.processLabel.y = 9;
            this.processLabel.mouseEnabled = false;
            this.kickOutBtn = ObjCreate.createGButton("", 200, 10, 19, 19, this, "CloseButtonBlue");
            this.kickOutBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onButtonClick);
            this.kickOutBtn.drawNow();
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            var loc2=0;
            var loc3=0;
            super.data = arg1;
            if (arg1) 
            {
                this._isCross = arg1["isCross"];
                loc1 = arg1["player"] as SPublicMiniPlayer;
                loc2 = arg1["copyId"] as int;
                this.nameLabel.htmlText = HTMLUtil.addColor(loc1.name, "#B1EFFE");
                this.levelLabel.htmlText = HTMLUtil.addColor(loc1.level + "", "#B1EFFE");
                if (this._isCross) 
                {
                    this.processLabel.htmlText = HTMLUtil.addColor(Cache.instance.crossGroup.entityCopyProcess(loc1.entityId, loc2), "#FFFF00");
                }
                else 
                {
                    this.processLabel.htmlText = "";
                }
                loc3 = loc1.careerEnable != 0 ? loc1.careerEnable : loc1.career;
                if (CareerConfig.instance.getInfoByCode(loc3)) 
                {
                    this.careerLabel.htmlText = HTMLUtil.addColor(CareerConfig.instance.getInfoByCode(loc3).name, "#B1EFFE");
                }
                if (data.isCaption) 
                {
                    this._captainIcon.visible = true;
                }
                else 
                {
                    this._captainIcon.visible = false;
                }
                if (EntityUtil.equal(Cache.instance.role.entityInfo.entityId, loc1.entityId)) 
                {
                    this.kickOutBtn.visible = true;
                }
                else if (!this._isCross && EntityUtil.equal(Cache.instance.role.entityInfo.entityId, Cache.instance.group.captain) || this._isCross && EntityUtil.equal(Cache.instance.role.entityInfo.entityId, Cache.instance.crossGroup.captain)) 
                {
                    this.kickOutBtn.visible = true;
                }
                else 
                {
                    this.kickOutBtn.visible = false;
                }
            }
            return;
        }

        /* internal  */onButtonClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var e: Object /* flash.events.MouseEvent */;
            var player: SPublicMiniPlayer;
            var textss: string;

            var loc1;
            player = null;
            textss = null;
            e = arg1;
            if (data) 
            {
                player = data["player"] as SPublicMiniPlayer;
                if (EntityUtil.toString(Cache.instance.role.entityInfo.entityId) != EntityUtil.toString(player.entityId)) 
                {
                    textss = this._isCross ? Language.getStringByParam(62319, player.name) : Language.getStringByParam(60113, player.name);
                    Alert.show(textss, Language.getString(69900), Alert.OK | Alert.CANCEL, null, (arg1: int): void
                    {
                        if (arg1 == Alert.OK) 
                        {
                            if (_isCross) 
                            {
                                Dispatcher.dispatchEvent(new DataEvent(EventName.CrossGroup_DoKickOut, player.entityId));
                            }
                            else 
                            {
                                Dispatcher.dispatchEvent(new DataEvent(EventName.Group_DoKickOut, player.entityId));
                            }
                        }
                        return;
                    })
                }
                else if (this._isCross) 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.CrossGroup_DoLeaveGroup, null));
                }
                else 
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.Group_DoLeaveGroup, null));
                }
            }
            return;
        }

        /* internal */ /* var */_captainIcon: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_isCross: Boolean;

        /* internal */ /* var */nameLabel: GLabel;

        /* internal */ /* var */levelLabel: GLabel;

        /* internal */ /* var */careerLabel: GLabel;

        /* internal */ /* var */processLabel: GLabel;

        /* internal */ /* var */_operMenuSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */kickOutBtn: GButton;

        /* internal */ /* var */inviteBtn: GButton;
    }
